package com.bbtShop.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bbtShop.aop.Login;
import com.bbtShop.core.model.*;
import com.bbtShop.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author manke
 * @Date 2020/10/13 15:24
 * @Version 0.0.1
 */
@Api(value = "UserController", description = "用户控制器")
@RestController
@RequestMapping("/User")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "getLisUser", notes = "获取用户列表")
    @PostMapping("/getLisUser")
    @Login(permission = "User:getLisUser")
    public ApiResponse<Object> getLisUser(@RequestParam(required = false) Integer pageNum,
                                          @RequestParam(required = false) Integer pageSize, @RequestBody User user) {
        return ApiResponse.success(userService.getLisUser(pageNum, pageSize, user));
    }

    @ApiOperation(value = "addUpdateUser", notes = "添加修改用户")
    @PostMapping("/addUpdateUser")
    @Login(permission = "User:addUpdateUser")
    public ApiResponse<Object> addUser(@RequestBody User user) {
        userService.addUpdateUser(user);
        return ApiResponse.success();
    }

    @ApiOperation(value = "delUser", notes = "删除用户")
    @PostMapping("/delUser")
    @Login(permission = "User:delUser")
    public ApiResponse<Object> delUser(@RequestBody Ids ids) {
        userService.delUser(ids);
        return ApiResponse.success();
    }

    @ApiOperation(value = "getUserInfo", notes = "获取用户详情信息")
    @PostMapping("/getUserInfo")
    @Login(permission = "User:getUserInfo")
    public ApiResponse<User> getUserInfo(@RequestBody User user) {
        return ApiResponse.success(userService.getUserInfo(user.getId()));
    }

    @ApiOperation(value = "getAllUser", notes = "获取所有用户名和id")
    @PostMapping("/getAllUser")
    @Login(permission = "User:getAllUser")
    public ApiResponse<List<UserDto>> getAllUser() {
        return ApiResponse.success(userService.getAllUser());
    }

}
